define(["angularAMD", 'moment'], function (angularAMD, moment) {
    angularAMD.service('$judgeSpcService', ['$rootScope', '$filter', '$translate', 'config', 'MMWService', '$mdDialog',
        function($rootScope, $filter, $translate, config, $MMWService, $mdDialog){
            var service = this;
            service.init=function(options, area){
                $mdDialog.dialog(
                    'module/moduleMobile/program/mobile01/judgeSpc.tmp.html',
                    function(dialog){
                        return {
                            inspectionInfo: options.inspectionInfo,
                            check_qty: 1,
                            check_time: new Date(),
                            back:function(){
                                dialog.hide();
                            },
                            confirm: function(){
                                var content = {
                                    op_no: options.inspectionInfo.op_no,
                                    plot_no: options.inspectionInfo.plot_no,
                                    employee_no: config.cache.account,
                                    area_no: options.area_no,
                                    machine_no: options.machine_no,
                                    check_qty: dialog.check_qty, // 預設檢驗數量是 1，當 SPC檢驗時，可以更改檢驗數量。
                                    check_time: moment(new Date()).format('YYYY-MM-DD HH:mm:ss'),
                                    productid: options.inspectionInfo.item_name,
                                    qc_result: 'Y',
                                    qc_type: '0', //首檢qc_type=0, 巡檢qc_type=1
                                    qc_reason_detail:[],
                                    run_type: 1 // run_type=0：一開始判斷要走SPC還是標準版帶 0 ; run_type=1：SPC檢驗和標準版檢驗送回資料帶 1。
                                };
                                
                                $MMWService.sendToServer({
                                    uri: 'ServicesSTD.Module_WIP.first_piece_check_process',
                                    content: content,
                                    success: function (data, response) {
                                        dialog.hide();
                                        $rootScope.showToast(response.Message);
                                    }
                                });
                            }
                        }
                    }
                )
            }
        }
    ]);
});